<template>
	<view style="margin-top: 20px;">


		<view class="home_content">

			<view class="" style="font-size: 16px;" @click="change_Img">
				头像
			</view>
			<view class="" style="display: flex;flex-direction: row;flex-wrap: nowrap;">
				<image :src="info.avatar" mode="" style="width: 30px;height: 30px;border-radius: 50%;" @click="change_Img"></image>
			</view>

		</view>

		<view class="home_content">
			<view class="" style="font-size: 16px;" @click="upname">
				昵称
			</view>
			<view class="" style="display: flex;flex-direction: row;flex-wrap: nowrap;" @click="upname">
				<text style="font-size: 16px; ">{{info.nickname}}</text>
				<image src="/static/images/next.png" mode="" style="width: 20px;height: 20px;"></image>
			</view>
		</view>
		<view class="home_content">
			<view class="" style="font-size: 16px;width: 300px;">
				账号
			</view>
			<view class="" style="display: flex;flex-direction: row;flex-wrap: nowrap;">
				<text style="font-size: 16px;display: inline-block;">{{info.account}}</text>
				
			</view>
		</view>
		<view class="home_content">
			<view class="" style="font-size: 16px;width: 300px;">
				手机号
			</view>
			<view class="" style="display: flex;flex-direction: row;flex-wrap: nowrap;">
				<text style="font-size: 16px; ">{{info.phone}}</text>
			</view>
		</view>
		<view class="home_content"  @click="togeren">
			<view class="" style="font-size: 16px;">
				个人简介
			</view>
			<view class="" style="display: flex;flex-direction: row;flex-wrap: nowrap;">
				<text style="font-size: 16px; display: inline-block;">{{info.synopsis}}</text>
				<image src="/static/images/next.png" mode="" style="width: 20px;height: 20px;"></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				customBarH: this.customBar,
				touxiang_Img: '',
				statusBarH: 0,
				info:[]
			}
		},
		onShow() {
			let token = uni.getStorageSync("token")
			uni.request({
				url: this.G_base + '/api/userinfo',
				method: "GET",
				header: {
					'content-type': 'application/x-www-form-urlencoded',
					'Authori-zation': 'Bearer ' + token
				},
				success: (res) => {
					console.log(res.data.data.data);
					this.info = res.data.data.data
					console.log(this.info)
				},
				fail: (err) => {
					console.log(err)
				}
			});
		},
		onLoad() {
			let token = uni.getStorageSync("token")
			uni.request({
				url: this.G_base + '/api/userinfo',
				method: "GET",
				header: {
					'content-type': 'application/x-www-form-urlencoded',
					'Authori-zation': 'Bearer ' + token
				},
				success: (res) => {
					console.log(res);
					this.info.img = res.data.data.data.avatar
					this.info.name = res.data.data.data.nickname
					this.info.account = res.data.data.data.account
					this.info.synopsis = res.data.data.data.synopsis

				},
				fail: (err) => {
					console.log(err)
				}
			});
		},
		methods: {
			upname() {
				uni.navigateTo({
					url: "/pages/updatausername/updatausername"
				})
			},
			togeren() {
				uni.navigateTo({
					url: "/pages/updatausername/gerenjianjie"
				})
			},
			test() {
				uni.navigateBack({
					delta: 1
				})
			},
			xiugaimima() {
				uni.navigateTo({
					url: "../xiugaimima/xiugaimima"
				})
			},
			change_Img() {
				let token = uni.getStorageSync("token")
				uni.chooseImage({
					success: (res) => {
						console.log(res)
						const tempFilePaths = res.tempFilePaths;
						console.log(res.tempFilePaths[0])
						uni.uploadFile({
							url: this.G_base + '/api/upload/image',
							filePath: res.tempFilePaths[0],
							name: 'file',
							method: 'post',
							header: {
								'Authori-zation': 'Bearer ' + token
							},
							success: (e) => {
								console.log(e)
								let data = e.data;
								let s = JSON.parse(data);
								this.touxiang_Img = s.data
								console.log(this.touxiang_Img)
								console.log(s)
								// 反馈图片地址

								console.log(s.data.url)
								let token = uni.getStorageSync("token")
								uni.request({
									url: this.G_base + '/api/user/edit',
									method: "POST",
									data: {
										avatar: s.data.url
									},
									header: {
										'content-type': 'application/x-www-form-urlencoded',
										'Authori-zation': 'Bearer ' + token
									},
									success: (res) => {
										console.log(res);
									},
									fail: (err) => {
										console.log(err)
									}
								});
								uni.showToast({
									title: "头像修改成功",
									icon: 'none'
								})
							},
							fail(e) {
								console.log(e)
							}
						});
					}
				});
			},
			// upimg(){

			// 	// uni.chooseImage({
			// 	//     count: 1, //默认9
			// 	//     sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
			// 	//     sourceType: ['album'], //从相册选择
			// 	//     success: function (res) {
			// 	//         console.log(JSON.stringify(res.tempFilePaths));
			// 	//     }
			// 	// });
			// 	// let token = uni.getStorageSync("token")
			// 	// uni.request({
			// 	//     url: this.G_base+'/api/user/edit',
			// 	//     data: {
			// 	// 		avatar:this.info.img,
			// 	// 		nickname:this.info.name
			// 	//     },
			// 	// 	method:"POST",
			// 	//     header: {
			// 	//         'content-type':'application/x-www-form-urlencoded' ,
			// 	// 		'Authori-zation': 'Bearer ' + token
			// 	//     },
			// 	//     success: (res) => {
			// 	//         console.log(res);

			// 	//     },
			// 	// 	fail: (err) => {
			// 	// 		console.log(err)
			// 	// 	}
			// 	// });
			// }
		},
	}
</script>

<style>
	.home_content image {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.home_contentlast {
		padding: 10px;
		margin: 20px 10px;
		display: flex;
		vertical-align: middle;
		justify-content: space-between;
		align-items: center;
	}

	.home_content {
		padding: 10px;
		margin: 20px 10px;
		border-bottom: 1px solid #EEEEEE;
		display: flex;
		vertical-align: middle;
		justify-content: space-between;
		align-items: center;
	}
</style>
